using System;
using System.IO;
using Velocity4Net.Ctx;

namespace Velocity4Net.Runtime.Parse.AST
{
    /**
     *  This file describes the interface between the Velocity code
     *  and the JavaCC generated code.
     *
     * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
     * @version $Id: Node.java 737539 2009-01-25 17:24:29Z nbubna $
     */

    public interface INode 
    {
        /** This method is called after the node has been made the current
         * node.  It indicates that child nodes can now be added to it. */
        void Open();

        /** This method is called after all the child nodes have been
          added.
         */
        void Close();

        /**
         * This pair of methods are used to inform the node of its
         * parent.
         * @param n
         *
         */
        void jjtSetParent(INode n);

        /**
         * @return The node parent.
         */
        INode jjtGetParent();

        /**
         * This method tells the node to add its argument to the node's
         * list of children.
         * @param n
         * @param i
         */
        void jjtAddChild(INode n, int i);

        /**
         * This method returns a child node.  The children are numbered
         * from zero, left to right.
         * @param i
         * @return A child node.
         */
        INode jjtGetChild(int i);

        /**
         * Return the number of children the node has.
         * @return The number of children of this node.
         */
        int jjtGetNumChildren();

        /**
         * @param visitor
         * @param data
         * @return The Node execution result object.
         */
        Object Accept(ParserVisitor visitor, Object data);

        /*
         * ========================================================================
         *
         * The following methods are not generated automatically be the Parser but
         * added manually to be used by Velocity.
         *
         * ========================================================================
         */

        /**
         * @see #jjtAccept(ParserVisitor, Object)
         * @param visitor
         * @param data
         * @return The node execution result.
         */
        Object childrenAccept(ParserVisitor visitor, Object data);

        /**
         * @return The first token.
         */
        Token FirstToken { get; }
        /**
         * @return The last token.
         */
        Token LastToken { get; }
        /**
         * @return The NodeType.
         */
        int NodeType { get; }

        /**
         * @param context
         * @param data
         * @return The init result.
         * @throws TemplateInitException
         */
        Object Init(InternalContextAdapter context, Object data);

        /**
         * @param context
         * @return The evaluation result.
         * @throws MethodInvocationException
         */
        bool Evaluate(InternalContextAdapter context);

        /**
         * @param context
         * @return The node value.
         * @throws MethodInvocationException
         */
        Object GetValue(InternalContextAdapter context);

        /**
         * @param context
         * @param writer
         * @return True if the node rendered successfully.
         * @throws IOException
         * @throws MethodInvocationException
         * @throws ParseErrorException
         * @throws ResourceNotFoundException
         */
        bool Render(InternalContextAdapter context, TextWriter writer);

        /**
         * @param o
         * @param context
         * @return The execution result.
         * @throws MethodInvocationException
         */
        Object Execute(Object o, InternalContextAdapter context);

        /**
         * @return The current node info.
         */
        int Info { get; set; }

        /**
         * @return A literal.
         */
        String Literal();


        /**
         * @return True if the node is invalid.
         */
        bool Invalid { get; set; }

        /**
         * @return The current line position.
         */
        int Line { get; }

        /**
         * @return The current column position.
         */
        int Column { get; }

        /**
         * @return the file name of the template
         */
        String TemplateName { get; }
    }
}
